<!-- 签约团队-详情资料 -->
<template>
	<publicPage officialAccount>
		<view class="addConsultPage" v-show="!loading">
			<InfoCard
				:item="{
					headimg: infoObj.teamImg,
					userName: infoObj.teamName,
					postName: infoObj.teamProfile,
				}"
			/>
			<view class="mt-5 mb-20 mx-15" style="background-color: #f5f5f5">
				<u--textarea
					v-model="apText"
					placeholder="请输入内容"
					border="none"
					height="230rpx"
				></u--textarea>
			</view>
			<view class="px-50 py-5">
				<u-button
					type="primary"
					text="立即签约"
					:customStyle="{
						fontSize: '32rpx',
						borderRadius: '20rpx',
						height: '88rpx',
					}"
					:throttleTime="500"
					@click="addFn"
				></u-button>
			</view>
		</view>

		<NoLogin
			:show="loginShow"
			tips="点击立即登录,登录后即可申请签约"
			@close="loginShow = false"
			@loginReturn="getList"
		/>

		<u-popup
			:show="editUserInfoShow"
			:round="10"
			:customStyle="{ height: '720rpx' }"
			:closeOnClickOverlay="false"
			:safeAreaInsetBottom="false"
		>
			<view class="linh-50 tc fz-16 fw-5 color8">请先完善用户信息</view>
			<MyInfo isComponents @editSuccess="editUserInfoShow = false" />
		</u-popup>

		<OfficialAccount :show="accountShow" @close="_closeFn" />
	</publicPage>
</template>

<script>
import InfoCard from "../components/infoCard.vue";
import MyInfo from "../myInfo/index.vue";
import orderApi from "@/api/order.js";
import NoLogin from "../components/noLogin.vue";
import OfficialAccount from "@/components/officialAccount.vue";


export default {
  components: {
    InfoCard,
    MyInfo,
    NoLogin,
    OfficialAccount
  },
  computed: {
    // 用户信息
    userInfo() {
      return this.$store.state.userInfo;
    }
  },
  data() {
    return {
      loading: true, // 是否加载中
      loginShow: false,
      getParams: {},
      infoObj: {},
      apText: "",
      editUserInfoShow: false,
      accountShow: false
    };
  },
  onLoad(options){
    const that = this
    if(options.scene){
      // 扫码进入
      that.getParams.teamId = options.scene

      if(!that.$store.state.userInfo.token || !that.$store.state.userInfo.id){
        this.loginShow = true
        return
      }
    }else{
      that.getParams = options
    }
    that.getList()
  },
  methods: {
    // 获取团队详情
    async getList() {
      const { data } = await orderApi.teamDetail(this.getParams.teamId);
      if(data.isTeamMember === 1){
        uni.redirectTo({
          url: `/pagesC/team/index?teamId=${this.getParams.teamId}`
        });
        return
      }
      this.infoObj = data;
      this.loading = false

      // 用户信息未完善
      if(!this.userInfo.userName || !this.userInfo.headimg || !this.userInfo.birthday){
        this.editUserInfoShow = true
      }
    },
    // 签约专家
    addFn() {
      const that = this
      let params = {
        teamId: that.getParams.teamId,
        userId: that.$store.state.userInfo.id,
        userType: "1", // 用户类型： 0专家 1用户
        applyContent: that.apText,
      }

      orderApi.userSignTeam(params).then(res=>{
        uni.showToast({
          title: '签约成功',
          icon: 'none',
          complete: ()=>{
            setTimeout(() => {
              if(!that.userInfo.mpOpenid){ // 未关注公众号
                that.accountShow = true
              }else{
                that.goBack()
              }
            }, 1500);
          }
        });
      })
    },
    // 关闭公众号弹窗
    _closeFn(){
      this.accountShow = false
      this.goBack()
    }
  },
};
</script>
<style lang="scss" scoped>
.addConsultPage {
	height: 100%;
	background-color: #ffffff;
}
</style>
<style scoped>
.addConsultPage >>> .u-textarea {
	background-color: inherit !important;
}
</style>
